package com.yangjunli.bishe.core;

import com.yangjunli.bishe.entity.User;

import javax.servlet.http.HttpServletRequest;

/**
 * @description:
 * @author: fzx
 * @time: 2020/1/3 13:29
 */
public class RequestHolder {

    private static final ThreadLocal<User> ACCESS_TOKEN_HOLDER = new ThreadLocal<>();

    private static final ThreadLocal<HttpServletRequest> REQUEST_HOLDER = new ThreadLocal<>();

    public static void add(User accessToken) {
        ACCESS_TOKEN_HOLDER.set(accessToken);
    }

    public static void add(HttpServletRequest request) {
        REQUEST_HOLDER.set(request);
    }

    public static User getAccessToken() {
        return ACCESS_TOKEN_HOLDER.get();
    }

    public static HttpServletRequest getCurrentRequest() {
        return REQUEST_HOLDER.get();
    }

    public static void remove() {
        ACCESS_TOKEN_HOLDER.remove();
        REQUEST_HOLDER.remove();
    }

}
